﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IceDog.DNL.CSharp.DesignPattern.InterceptingFilterPattern.WebReq
{
    /// <summary>
    /// 过滤器链（Filter Chain） - 过滤器链带有多个过滤器，并在 Target 上按照定义的顺序执行这些过滤器。
    /// </summary>
    public class FilterChain
    {
        private List<IFilter> _filters = new List<IFilter>();
        private Target target;

        public void AddFilter(IFilter filter)
        {
            _filters.Add(filter);
        }

        public void Execute(RequestType requestType)
        {
            foreach (IFilter filter in _filters)
            {
                filter.Execute(requestType);
            }
            target.Execute(requestType);
        }

        public void SetTarget(Target target)
        {
            this.target = target;
        }
    }
}
